home *** CD-ROM | disk | FTP | other *** search
- Path: aimnet.aimnet.com!not-for-mail
- From: jmcneill@aimnet.com (Jonathan S. McNeill)
- Newsgroups: comp.lang.c,comp.unix.programmer
- Subject: Re: Q: '\n' character
- Date: 2 Apr 1996 11:42:27 -0800
- Organization: Aimnet Corporation
- Sender: jmcneill@aimnet.com
- Message-ID: <4jrvv3$ask@aimnet.aimnet.com>
- References: <31616F63.481D@lava.weeg.uiowa.edu>
- NNTP-Posting-Host: aimnet.aimnet.com
-
- In article <31616F63.481D@lava.weeg.uiowa.edu>,
- Artur Wojdat <awojdat@lava.weeg.uiowa.edu> wrote:
-
- > Is there a function or some sort of way that I could remove '\n'
- >charecter form the end of the string. I'm reading from two files, want to
- >form one line of text and then have it printed out to stdout. I use fgets to
- >read from the file and I noticed that it appends newline char at the end.
-
- Well, if you want ultimate control over your data, just use a loop and
- get a character at a time. Disclaimer: the following is an example, has
- not been tested, and I agree that there are about a million ways you could do
- this.
-
- /*
- * loop through characters until newline or end of file
- */
- while ( (ch = getc(stream)) != '\n' && ch != EOF ) {
-
- sprintf(buffer, "%s%c", buffer, ch);
- }
-
- /*
- * add a trailing nul character so that you can use string functions
- */
- sprintf(buffer, "%s\0");
-
- Hope this helps-
-
- R/
- Jon McNeill
- jmcneill@aimnet.com
-